package com.xzmzhp.dao.finance;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xzmzhp.dao.finance.SQL.FinanceSql;
import com.xzmzhp.pojo.finance.Finance;
import com.xzmzhp.vo.finance.FinanceVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author: 王源(xm)
 * @create: 2022-03-25 20:13
 * @program: ams
 * @description: 财务信息数据库交互类
 */
@Repository
public interface FinanceMapper extends BaseMapper<Finance> {

    /**
     * 根据财务id查询财务信息
     * @param financeId 财务id
     * @return 财务信息
     */
    @Select("select finance.finance_id,finance.finances_date,finance.finance_amounts,finance.cash_flow,finance.finances.details,finances.finances_type_id,finances_type.finances_type_name" +
            "finance.finance_pass,finance.finances_personnel_id,personnel.personnel_name,personnel.personnel_phone from finances,finances_type,personnel " +
            "where finance.finance_id = #{financeId} and finance.finances_type_id = finances_type.finances_type_id and finance.finances_personnel_id = personnel.personnelId")
    FinanceVo findFinanceVoById(@Param("financeId") Integer financeId);

    /**
     * 查询所有财务数据
     * @return 财务信息
     */
    @Select("select finance.finance_id,finance.finances_date,finance.finance_amounts,finance.cash_flow,finance.finances.details,finances.finances_type_id,finances_type.finances_type_name" +
            "finance.finance_pass,finance.finances_personnel_id,personnel.personnel_name,personnel.personnel_phone from finances,finances_type,personnel " +
            "where finance.finances_type_id = finances_type.finances_type_id and finance.finances_personnel_id = personnel.personnelId")
    List<FinanceVo> findAll();

    /**
     * 根据条件查询财务信息
     * @param params 参数
     *        cashFlow  收支类型
     *        financesTypeId 收支项目id
     *        financesPass 是否通过
     *        personnelName  收支人员姓名
     *        startTime 起始时间
     *        endTime 结束时间
     * @return 相应财务信息
     */
    @SelectProvider(type = FinanceSql.class,method = "findFinanceVoByParam")
    List<FinanceVo> findFinanceVoByParam(Map<String,Object> params);

}
